# coding=utf-8
from mod.common.mod import Mod

from bedcore.common import cls2path
from modInfo import ModInfo


@Mod.Binding(ModInfo.NAME, ModInfo.VERSION)
class ModMain(object):

    def getServerComponents(self):
        return []

    def getClientComponents(self):
        return []

    def getServerSystems(self):
        from server.mainSystem import MainSystem
        return [
            ('main', MainSystem),
        ]

    def getClientSystems(self):
        from client.mainSystem import MainSystem
        return [
            ('main', MainSystem),
        ]

    @Mod.InitServer()
    def serverInitialize(self):
        from bedcore.server import serverApi
        for compName, compCls in self.getServerComponents():
            serverApi.RegisterComponent(ModInfo.NAME, compName, cls2path(compCls))
        for sysName, sysCls in self.getServerSystems():
            serverApi.RegisterSystem(ModInfo.NAME, sysName, cls2path(sysCls))
        ModInfo.RUNNING_SERVER = True

    @Mod.DestroyServer()
    def serverDestroy(self):
        ModInfo.RUNNING_SERVER = False

    @Mod.InitClient()
    def clientInitialize(self):
        from bedcore.client import clientApi
        for compName, compCls in self.getClientComponents():
            clientApi.RegisterComponent(ModInfo.NAME, compName, cls2path(compCls))
        for sysName, sysCls in self.getClientSystems():
            clientApi.RegisterSystem(ModInfo.NAME, sysName, cls2path(sysCls))
        ModInfo.RUNNING_CLIENT = True

    @Mod.DestroyClient()
    def clientDestroy(self):
        ModInfo.RUNNING_CLIENT = False
